package top.itmeans.yes.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import top.itmeans.yes.entity.SkuStock;
import top.itmeans.yes.mapper.SkuStockMapper;
import top.itmeans.yes.service.SkuStockService;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * sku的库存 服务实现类
 * </p>
 *
 * @author Yiming.Cao
 * @since 2022-05-12
 */
@Service
public class SkuStockServiceImpl extends ServiceImpl<SkuStockMapper, SkuStock> implements SkuStockService {
    @Resource
    private SkuStockMapper skuStockMapper;

    @Override
    public List<SkuStock> getList(Long pid, String keyword) {
        LambdaQueryWrapper<SkuStock> skuStockQueryWrapper = new LambdaQueryWrapper<>();
        skuStockQueryWrapper.eq(SkuStock::getProductId,pid);
        skuStockQueryWrapper.like(!StrUtil.isEmpty(keyword),SkuStock::getSkuCode,keyword);
        return skuStockMapper.selectList(skuStockQueryWrapper);
    }

    @Override
    public int update(Long pid, List<SkuStock> skuStockList) {

        return skuStockMapper.replaceList(skuStockList);
    }
}
